package com.edu.exam.entity.grading.correction;

import com.edu.exam.enums.grading.CorrectionOperationType;
import com.edu.exam.enums.grading.CorrectionOperationResult;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.time.LocalDateTime;

/**
 * 修正历史实体类
 *
 * <p>所属模块：E-02 阅卷管理模块</p>
 * <p>对应数据库表：correction_history</p>
 *
 * <p>记录成绩修正的历史操作信息，包括操作类型、操作描述、
 * 操作时间、原值、新值等关键信息。支持修正过程的完整追溯。</p>
 *
 * @author System
 * @version 1.0.0
 */
@Entity
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class CorrectionHistory {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @NotNull(message = "修正ID不能为空")
    @Column(name = "correction_id", nullable = false)
    private Long correctionId;

    @NotNull(message = "操作类型不能为空")
    @Enumerated(EnumType.STRING)
    @Column(name = "operation_type", nullable = false, length = 20)
    private CorrectionOperationType operationType;

    @NotBlank(message = "操作描述不能为空")
    @Size(max = 1000, message = "操作描述长度不能超过1000个字符")
    @Column(name = "operation_description", nullable = false, columnDefinition = "TEXT")
    private String operationDescription;

    @NotNull(message = "操作人ID不能为空")
    @Column(name = "operator_id", nullable = false)
    private Long operatorId;

    @Size(max = 100, message = "操作人姓名长度不能超过100个字符")
    @Column(name = "operator_name", length = 100)
    private String operatorName;

    @NotNull(message = "操作时间不能为空")
    @Column(name = "operation_time", nullable = false, updatable = false)
    private LocalDateTime operationTime;

    @Size(max = 2000, message = "原值长度不能超过2000个字符")
    @Column(name = "old_value", columnDefinition = "TEXT")
    private String oldValue;

    @Size(max = 2000, message = "新值长度不能超过2000个字符")
    @Column(name = "new_value", columnDefinition = "TEXT")
    private String newValue;

    @Size(max = 1000, message = "操作备注长度不能超过1000个字符")
    @Column(name = "operation_remarks", columnDefinition = "TEXT")
    private String operationRemarks;

    @Size(max = 100, message = "客户端IP地址长度不能超过100个字符")
    @Column(name = "client_ip_address", length = 100)
    private String clientIpAddress;

    @Enumerated(EnumType.STRING)
    @Column(name = "operation_result", length = 20)
    @Builder.Default
    private CorrectionOperationResult operationResult = CorrectionOperationResult.SUCCESS;

    @Column(name = "deleted", nullable = false)
    @Builder.Default
    private Boolean deleted = false;

    // 标准审计字段
    @CreationTimestamp
    @Column(name = "created_time", nullable = false, updatable = false)
    private LocalDateTime createdTime;

    @UpdateTimestamp
    @Column(name = "updated_time", nullable = false)
    private LocalDateTime updatedTime;

    @Version
    @Column(name = "version", nullable = false)
    @Builder.Default
    private Integer version = 0;

    @Column(name = "is_deleted", nullable = false)
    @Builder.Default
    private Boolean isDeleted = false;
}